@extends("layouts.backend.webadmin")

@section('content')
    <style>
        #searchCategory{
            border-radius:0px;}
    </style>
<link rel="stylesheet" href="{{env('APP_ROOT')}}/assets/select2/css/select2.min.css">
<link rel="stylesheet" href="{{env('APP_ROOT')}}/assets/select2/css/select2totree.css">
<link rel="stylesheet" href="{{env('APP_ROOT')}}/assets/layui/css/layui.css">
<link rel="stylesheet" href="{{env('APP_ROOT')}}/css/vulslist.css">
<script src="{{env('APP_ROOT')}}/assets/layui/layui.all.js"></script>
<script src="{{env('APP_ROOT')}}/js/common.js"></script>
<!-- Content Header (Page header) -->

<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <a class="btn btn-primary vuls-add" href="{{ URL::route('admin.flaw.vulsadd') }}" role="button"><i class="fa fa-plus-square" aria-hidden="true"></i> 提交漏洞</a>
                    <a class="btn btn-info" href="javascript:;" role="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-bars"></i> 搜索</a>
                    {{--回收站功能暂不开放 -- start --}}
                    {{--                    <a class="btn btn-warning vuls-restore" href="{{ URL::route('admin.flaw.vulslist',['type'=>1]) }}" role="button"><i class="fa fa-trash-o" aria-hidden="true"></i> 回收站</a>--}}
                    {{--回收站功能暂不开放 -- end --}}
                </div>
                <!-- 搜索开始-->
                <form class="form-inline" role="form" action="{{ URL::route('admin.flaw.search') }}" method="post" onsubmit="return checkForm()">
                    <div class="box-body">
                        <div class="">
                            <div class="form-group date">
                                <label for="startTime col-sm-2">时间:</label>
                                <div class="input-group col-sm-10">
                                <input type="text" class="form-control pull-left" id="startTime" placeholder="开始时间" name="startTime" value="@if(isset($request->startTime)){{  $request->startTime }}@endif">
                                    <div class="input-group-addon">
                                        <i class="fa fa-calendar"></i>
                                    </div>
                                    <input type="text" class="form-control pull-left" id="endTime" placeholder="结束时间" name="endTime" value="@if(isset($request->endTime)){{  $request->endTime }}@endif">
                                    <div class="input-group-addon">
                                        <i class="fa fa-calendar"></i>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="uName">提交人:</label>
                                <div class="form-group">
                                <select class="form-control select2" name="uName" id="uName">
                                    <option value=""> 所有</option>
                                    @foreach($ulists as $ulist)
                                    <option value="{{$ulist->id}}" @if ((isset($request->uName) ? $request->uName : '-1') == $ulist->id)  selected @endif>{{$ulist->name}}</option>
                                    @endforeach
                                </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="searchCategory"  >所属分类:</label>
                                <div class="form-group  ">
                                <select class="form-control select2"   name="searchCategory" id="searchCategory">
                                    <option value="">所有</option>
                                    @foreach($categorys as $category)
                                        <option class="l{{$category->num}} {{$category->child=='yes'?'non-leaf':''}}" data-pup="{{$category->pid}}" value="{{$category->id}}" @if ((isset($request->searchCategory) ? $request->searchCategory : '-1') == $category->id)  selected @endif>{{$category->name}}</option>
                                    @endforeach
                                </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="searchLevel"  >漏洞级别:</label>
                                <div class="form-group  ">
                                <select class="form-control select2"   name="searchLevel" id="searchLevel">
                                    <option value="">所有</option>
                                    @foreach($levels as $level)
                                        <option value="{{$level->id}}" @if ((isset($request->searchLevel) ? $request->searchLevel : '-1') == $level->id)  selected @endif>{{$level->name}}</option>
                                    @endforeach
                                </select>
                                </div>
                            </div>
                            <div class="form-group ">
                                <label for="searchStatus"   >漏洞状态:</label>
                                <div class="form-group  ">
                                <select class="form-control select2"   id="searchStatus" name="searchStatus">
                                    <option value="">所有</option>
                                    @for($i=0;$i<count($vulStatus);$i++)
                                        @if($i != 1 && $i != 9 && $i != 10)
                                        <option value="{{$i}}" @if ((isset($request->searchStatus) ? $request->searchStatus : '-1') == $i)  selected @endif>{{ $vulStatus[$i][0]}}</option>
                                        @endif
                                    @endfor
                                </select>
                                </div>
                            </div>
                            {{--v1.1版本更换ajax选择为select直接选择 start--}}
                            <div class=" form-group">
                                <label for="searchOgz"   >所属机构</label>
                                <div class="form-group ">
                                <select class="form-control select2"   id="searchOgz" name="searchOgz">
                                    <option value="">所有</option>
                                @foreach($ogzs as $ogz)
                                    <option class="l{{$ogz->num}} {{$ogz->child=='yes'?'non-leaf':''}}" data-pup="{{$ogz->pid}}" value="{{$ogz->id}}"
                                            @if ((isset($request->searchOgz) ? $request->searchOgz : '-1') == $ogz->id)  selected @endif
                                            @if ($ogz->hasaccess == 'non')  disabled="disabled" @endif
                                    >{{$ogz->name}}</option>
                                @endforeach
                                </select>
                                </div>
                            </div>
                            {{--v1.1版本更换ajax选择为select直接选择 end--}}
                            {{--v1.1 版本取消子版块搜索条件 start--}}
{{--                            <div class=" form-group">
                                <label for="searchChild"   >子版块</label>
                                <div class="form-group">
                                <select class="form-control select2"   id="searchChild" name="searchChild">
                                    <option value="">所有</option>
                                    @if(isset($childsOgz))
                                    @foreach($childsOgz as $ogz)
                                        <option value="{{$ogz->id}}" @if ((isset($childId) ? $childId : '-1') == $ogz->id)  selected @endif>{{$ogz->name}}</option>
                                    @endforeach
                                    @endif
                                </select>
                                </div>
                            </div>--}}
                            {{--v1.1 版本取消子版块搜索条件 end--}}
                            <div class=" form-group">
                                <label for="searchApp"   >应用名称</label>
                                <div class="form-group">
                                <select class="form-control select2"   id="searchApp" name="searchApp">
                                    <option value="">所有</option>
                                    @if(isset($apps))
                                    @foreach($apps as $ogz)
                                        <option value="{{$ogz->id}}" @if ((isset($app) ? $app : '-1') == $ogz->id)  selected @endif>{{$ogz->name}}</option>
                                    @endforeach
                                    @endif
                                </select>
                                </div>
                            </div>
                            {{--功能暂不开放 --start --}}
{{--                            <div class=" form-group">
                                <label for="searchDel"   >是否删除</label>
                                <div class="form-group">
                                <select class="form-control select2"   id="searchDel" name="searchDel">
                                    <option selected="selected" value="">所有</option>
                                    <option  value="1" @if ((isset($request->searchDel) ? $request->searchDel : '2') == 1)  selected @endif>是</option>
                                    <option value="0" @if ((isset($request->searchDel) ? $request->searchDel : '2') == 0)  selected @endif>否</option>
                                </select>
                                </div>
                            </div>--}}
                            {{--功能暂不开放 --end --}}
                            <div class="form-group">
                                <label for="searchKeywords"   >关键字</label>
                                <div class="form-group">
                                <input type="text" class="form-control" id="searchKeywords" placeholder="标题/副标题" name="searchKeywords"
                                       value="{{isset($request->searchKeywords) ? $request->searchKeywords : ''}}">

                                </div>
                            </div>
                           <div class="form-group">
                               <label for="searchbtn"> </label>
                               <button type="submit" class=" btn btn-primary" name="searchbtn"><i class="fa fa-search"></i>搜索</button>
                               <a  href="{{route('admin.flaw.export')}}" type="button" class=" btn btn-success addition-export" name="importbtn"><i class="fa fa-download"></i>导出</a>
                           </div>
                        </div>
                        <!-- /.row -->
                    </div>
                    {!! csrf_field() !!}
                </form>
                <!-- 搜索结束-->
                <!-- /.box-header -->
                <div class="box-body1">
                    <table width="100%" id="leveltable" class="table table-bordered table-striped">
                        <thead>
                        <tr>
                            <td rowspan="1" colspan="10">
                                <a href="{{ URL::route('admin.flaw.search',['searchStatus'=>0]) }}">待审核（<span>{{$static[0]}}</span>）</a>
                                <a href="{{ URL::route('admin.flaw.search',['searchStatus'=>2]) }}">待确认（<span>{{$static[1]}}</span>）</a>
                                <a href="{{ URL::route('admin.flaw.search',['searchStatus'=>3]) }}">待修复（<span>{{$static[2]}}</span>）</a>
                                <a href="{{ URL::route('admin.flaw.search',['searchStatus'=>4]) }}">已修复（<span>{{$static[3]}}</span>）</a>
                                <a href="{{ URL::route('admin.flaw.search',['searchStatus'=>7]) }}">申诉中（<span>{{$static[4]}}</span>）</a>
                                <a href="{{ URL::route('admin.flaw.search',['searchStatus'=>100]) }}">待评分（<span>{{$static[5]}}</span>）</a>
                            </td>
                        </tr>
                        <tr>
{{--                            <th>#</th>--}}
                            <th>编号</th>
                            <th>标题</th>
                            <th>提交人</th>
                            <th class="control-width">应用名称</th>
                            <th class="control-width">所属分类</th>
                            <th class="control-width">漏洞级别</th>
{{--                            <th>积分 / 安全币</th>--}}
                            <th class="control-width">状态</th>
                            <th class="control-width">漏洞价值</th>
                            <th>更新日期</th>
                            {{--功能暂不开放 --start --}}
{{--                            <th>是否删除</th>
                            <th>删除日期</th>--}}
                            {{--功能暂不开放 --end --}}
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach ($lists as $list)
                        <tr>
                            {{--<td>{{$list->id}}</td>--}}
                            <td>@if($list->vuls_number){{$list->vuls_number}}
                                @endif</td>
                            <td style="word-break: break-all;"><a href="
                            @php
                            /*if($list->status ==0 && access()->allowMultiple('vuls-checkForm')){
                            echo URL::route('admin.flaw.check',['id'=>$list->id]);
                            }elseif($list->status ==1 && access()->allowMultiple('vuls-checkedForm')){
                            echo URL::route('admin.flaw.checked',['id'=>$list->id]);
                            }elseif($list->status ==2 && access()->allowMultiple('vuls-ensureForm')){
                            echo URL::route('admin.flaw.ensure',['id'=>$list->id]);
                            }elseif($list->status ==3 && access()->allowMultiple('vuls-repairForm')){
                            echo URL::route('admin.flaw.repair',['id'=>$list->id]);
                            }elseif($list->status ==4 && access()->allowMultiple('vuls-confirmView')){
                            echo URL::route('admin.flaw.confirm',['id'=>$list->id]);
                            }elseif($list->status ==5 && access()->allowMultiple('vuls-solvedForm')){
                            echo URL::route('admin.flaw.solved',['id'=>$list->id]);
                            }elseif($list->status ==8 && access()->allowMultiple('vuls-ignoreForm')){
                            echo URL::route('admin.flaw.ignore',['id'=>$list->id]);
                            }elseif($list->status ==11 && access()->allowMultiple('vuls-noEffect')){
                            echo URL::route('admin.flaw.noEffect',['id'=>$list->id]);
                            }elseif($list->status ==6 && access()->allowMultiple('vuls-shutDownForm')){
                            echo URL::route('admin.flaw.shut',['id'=>$list->id]);
                            }elseif($list->status ==7 && access()->allowMultiple('vuls-appealFormView')){
                            echo URL::route('admin.flaw.appeal',['id'=>$list->id]);
                            }else{
                            echo URL::route('admin.flaw.vulsdetail',['id'=>$list->id]);
                            }*/
                            echo URL::route('admin.flaw.vulsdetail',['id'=>$list->id]);
                            @endphp
" target="_blank"> {{$list->title}}</a></td>
                            <td>{{$list->uname}} ( {{$list->account}} )</td>
                            <td align="center">{{$list->aname}}</td>
                            <td align="center">{{$list->cname}}</td>
                            <!--背景色-->
                            <td align="center" style="color:
                            @if($list->level_id==1) #DF2935;
                            @elseif($list->level_id==2) #F3752B;
                            @elseif($list->level_id==3) #F1D302;
                            @elseif($list->level_id==4) #86BA90;
                            @endif">
                                {{$list->lname}}
                            </td>
{{--                            <td>{{$list->credit}} / {{$list->reward}}</td>--}}
{{--                            <td>{{$list->credit}}</td>--}}
                            <td align="center">{{$vulStatus[$list->status][0]}}</td>
                            <td>{{$list->value}}</td>
                            <td>@php echo substr($list->updated_at,0,11);@endphp</td>
                            {{--功能暂不开放 --start --}}
{{--                            <td>@if($list->is_delete==1)是 @else 否 @endif</td>
                            <td>@php echo substr($list->delete_at,0,11);@endphp</td>--}}
                            {{--功能暂不开放 --end --}}
                            <td>
                                @if($type==0)

                                @if($list->status ==0)
                                <a  style="background: #DF2935;color: white;" class="btn btn-sm vuls-checkForm" href="{{  URL::route('admin.flaw.check',['id'=>$list->id]) }}" role="button"><i class="fa fa-pencil fa-fw"></i>待审核</a>
                                @elseif($list->status ==1)
                                        <a style="background: #F3752B;color: white;" class="btn btn-sm vuls-checkedForm" href="{{ URL::route('admin.flaw.checked',['id'=>$list->id]) }}" role="button"><i class="fa fa-pencil fa-fw"></i>已审核</a>
                                @elseif($list->status ==2)
                                <a style="background: #F3752B;color: white;" class="btn btn-sm vuls-ensureForm" href="{{ URL::route('admin.flaw.ensure',['id'=>$list->id]) }}" role="button"><i class="fa fa-pencil fa-fw"></i>待确认</a>
                                        <a class="btn btn-success btn-sm distribute-distribute disp " name="sentencepoints" role="button" data-id="{{$list->id}}"><i class="fa fa-pencil fa-fw"></i>分发</a>
                                @elseif($list->status ==3)
                                    <a style="background: #F1D302;color: white;" class="btn btn-sm vuls-repairForm" href="{{ URL::route('admin.flaw.repair',['id'=>$list->id]) }}" role="button"><i class="fa fa-pencil fa-fw"></i>待修复</a>
                                        <a class="btn btn-success btn-sm  distribute-distribute disp" name="sentencepoints" role="button" data-id="{{$list->id}}"><i class="fa fa-pencil fa-fw"></i>分发</a>
                                    @if($list->can_delay)
                                        <a href="{{route('admin.flaw.applypage')}}?vuls_id={{$list->id}}" class="btn btn-success btn-sm -vuls-delay" name="vul_delay" role="button" data-id="{{$list->id}}"><i class="fa fa-pencil fa-fw"></i>延期</a>
                                    @endif
                                    @if($list->audit_delay)
                                        <a href="{{route('admin.flaw.applypage')}}?vuls_id={{$list->id}}&audit=1" class="btn btn-success btn-sm -vuls-auditdelay" name="vul_delay_audit" role="button" data-id="{{$list->id}}"><i class="fa fa-pencil fa-fw"></i>审核</a>
                                    @endif
                                @elseif($list->status ==4)
                                    <a style="background: #86BA90;color: white;" class="btn btn-sm vuls-confirmView" href="{{ URL::route('admin.flaw.confirm',['id'=>$list->id]) }}" role="button"><i class="fa fa-pencil fa-fw"></i>已修复</a>
                                @elseif($list->status ==5)
                                    <a style="background: #bcbabe;color: white;" class="btn btn-sm vuls-solvedForm" href="{{ URL::route('admin.flaw.solved',['id'=>$list->id]) }}" role="button"><i class="fa fa-pencil fa-fw"></i>已解决</a>
                                @elseif($list->status ==8)
                                    <a style="background: #bcbabe;color: white;" class="btn btn-sm  vuls-ignoreForm" href="{{ URL::route('admin.flaw.ignore',['id'=>$list->id]) }}" role="button"><i class="fa fa-pencil fa-fw"></i>已忽略</a>
                                @elseif($list->status ==11)
                                    <a style="background: #bcbabe;color: white;" class="btn btn-sm  vuls-noEffect" href="{{ URL::route('admin.flaw.noEffect',['id'=>$list->id]) }}" role="button"><i class="fa fa-pencil fa-fw"></i>无影响</a>
                                    @elseif($list->status ==6)
                                        <a style="background: #bcbabe;color: white;" class="btn btn-sm  vuls-shutDownForm" href="{{ URL::route('admin.flaw.shut',['id'=>$list->id]) }}" role="button"><i class="fa fa-pencil fa-fw"></i>已关闭</a>
                                @elseif($list->status ==7)
                                        <a style="background: #DF2935;color: white;" class="btn btn-sm  vuls-appealFormView" href="{{ URL::route('admin.flaw.appeal',['id'=>$list->id]) }}" role="button"><i class="fa fa-pencil fa-fw"></i>申诉中</a>
                                @endif
                                @endif
                                    @if($list->is_reasonable <2 && in_array($list->status,array(3,4,5)))
                                        @if($list->source!=1)
                                    <a class="btn btn-success btn-sm vuls-sentencepoints" name="sentencepoints" role="button" data-id="{{$list->id}}"><i class="fa fa-pencil fa-fw"></i>评分确认</a>
                                        @endif
                                    @endif
                                    @if($list->is_reasonable ==3)
                                    <a class="btn btn-success btn-sm vuls-vulsreedit" name="vulsreedit" role="button" data-id="{{$list->id}}" data-level="{{$list->level_id}}" data-credit="{{$list->credit}}" data-reward="{{$list->reward}}"><i class="fa fa-pencil fa-fw"></i>重新评分</a>
                                     @endif
                            </td>
                        </tr>
                        @endforeach
                        </tbody>

                    </table>
                    {{$lists->links()}}
                </div>
                <!-- /.box-body -->
            </div>
            <!-- /.box -->
        </div>
        <!-- /.col -->
    </div>
    <!-- /.row -->
    <!-- 弹出层 判断等级是否合理-->
    <div class="layui-form" action="" id="hiddenform" style="display: none">
        <div class="layui-form-item">
            <label class="layui-form-label">是否合理</label>
            <div class="layui-input-block">
                <input type="radio" name="is_reasonable" value="2" title="是" checked class="radiobtn">
                <input type="radio" name="is_reasonable" value="3" title="否" class="radiobtn">
            </div>
        </div>
        <div class="layui-form-item layui-form-text layui-form-reason">
            <label class="layui-form-label">重判理由</label>
            <div class="layui-input-block">
                <textarea name="desc" placeholder="请简单描述等级评分不合理的理由." class="layui-textarea" cols="3" id="reasonConetnt"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo" id="levelConfirm">确认</button>
            </div>
        </div>
        <input type="hidden" id="hiddenId" value="">
    </div>
    <!-- 弹出层 -->
    <!-- 弹出层 重新编辑等级-->
    <div class="" action="" id="editForm"  style="display: none">
        <div class="layui-form-item">
            <label class="layui-form-label">选择等级</label>
            <div class="layui-input-block">
                <select name="editLevel" lay-filter="aihao" id="parentLevel">
                    <option value="">默认等级</option>
                    @foreach($levels as $level)
                        <option value="{{$level->id}}">{{$level->name}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">选择积分</label>
            <div class="layui-input-block">
                <select name="editPoints" lay-filter="aihao" id="childPoints">
                    <option value="">默认值</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">选择安全币</label>
            <div class="layui-input-block">
                <select name="editReward" lay-filter="aihao" id="childReward">
                    <option value="">默认值</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo" id="editConfirm">确认</button>
            </div>
        </div>
        <input type="hidden" id="hiddenEditId" value="">
    </div>
    <!-- 弹出层 重新编辑等级 -->

    <!-- 弹出层 分发开始-->


    <div id="distributeform" style="display: none">
        <div class="parents">
            <div style="height: 30px;width: 100%"></div>
            <div class="layui-form-item">
                <label class="layui-form-label">添加分发人员</label>
                <div class="layui-input-block">
                    <div class="input-group dropdown" style="width: 60%;">
                        {{--<span class="input-group-addon">$</span>--}}
                        <input type="text" name="title" required lay-verify="required" placeholder="请输入员工账号"
                               autocomplete="off" class="layui-input mysearch form-control">
                        <span class="input-group-addon check " data-toggle="dropdown" style="cursor:pointer;">验证</span>
                        <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">


                        </ul>
                    </div>

                </div>
            </div>


            <div style="height: 10px;border-bottom: dashed 1px #e2e2e2">
            </div>
            <div style="margin-left: 20px;margin-top: 20px;height:170px;">
                <div style="height: 20px;"><span class="label label-info">分发人员信息</span></div>
                <div class="addaccount" style="padding: 2px;">

                </div>
            </div>
            <div class="clearfix" style="height: 10px;border-bottom: dashed 1px #eee">
            </div>
            <div class="layui-form-item" >
                <div class="layui-input-block pull-right" style="padding: 10px;">
                    <input type="hidden" id="distributeId" value="">
                    <button onclick="submits(this)" class="btn btn-primary" lay-submit lay-filter="formDemo">立即提交
                    </button>
                </div>
            </div>

        </div>
    </div>
@include('backend.flaw.vulsdelay')
    <!-- 弹出层 分发结束-->
</section>
<!-- /.content -->
@stop

@section('javascript-end')
    <script src="{{env('APP_ROOT')}}/assets/select2/js/select2.min.js"></script>
    <script src="{{env('APP_ROOT')}}/assets/select2/js/select2totree.js"></script>
    <script>
        $('#searchCategory').select2ToTree({"border-radius":'0px'});
        $('#searchOgz').select2ToTree({"border-radius":'0px'});
        $('#searchApp').select2({"border-radius":'0px'});
        $('#leveltable').DataTable({
            'paging'      : false,
            'lengthChange': false,
            'searching'   : false,
            'ordering'    : false,
            'info'        : false,
            'autoWidth'   : true,
            'pagingType': "simple_numbers",  //分页样式：simple,simple_numbers,full,full_numbers
            'oLanguage'     :{
                'sUrl'    : '{{env("APP_ROOT")}}/assets/bootstrap/js/zh_cn.json'
            },
            'columnDefs': [{
                "targets": 1,
                "width": '150px'
            }]
        });
        $(function () {
            //渲染表单元素
            layui.form.render();
            //日历插件
             $('#startTime,#endTime').datepicker({
                 autoclose: true
             });
            //所属机构联动--一级联动
            $('#searchOgz').change(function(){
                var v = $(this).val();
                $('#searchApp option').not(":first").remove();
                if(!v) v = -1;
                $.get('{{env("APP_ROOT")}}/admin/appajaxreturn/id/'+v,function(msg){
                     if(msg){
                         var html = '';
                         for(var index  in msg){
                             html +="<option value="+msg[index]['id']+">"+msg[index]['name']+"</option>";
                         }
                         $('#searchApp option').not(":first").remove();
                         $('#searchApp').append(html);
                     }else{
                      return false;
                     }
                })
            });
            //二级联动
            {{-- v1.1版本取消子版块 start--}}
            {{--$('#searchChild').change(function(){--}}
                {{--var v = $(this).val();--}}
                {{--if(!v){--}}
                    {{--v =$("#searchOgz :selected").val() || !1;--}}
                {{--}--}}
                {{--$.get('{{env("APP_ROOT")}}/admin/searchAjax/type/child/id/'+v,function(msg){--}}
                    {{--if(msg){--}}
                        {{--var html = '';--}}
                        {{--for(var index  in msg){--}}
                            {{--html +="<option value="+msg[index]['id']+">"+msg[index]['name']+"</option>";--}}
                        {{--}--}}
                        {{--$('#searchApp option').not(":first").remove();--}}
                        {{--$('#searchApp').append(html);--}}
                    {{--}else{--}}
                        {{--return false;--}}
                    {{--}--}}
                {{--})--}}
            {{--});--}}
            {{-- v1.1版本取消子版块 end--}}
            //等级评分确认操作
            $('.layui-unselect').each(function(){
                $(this).click(function(){
                    var radioVal = $(this).prev().val();
                    radioVal==3 ? $('.layui-form-reason').show(): $('.layui-form-reason').hide();
//                    radioVal==2 ? $('.layui-btn').addClass('layui-btn-addClass'): $('.layui-btn').removeClass('layui-btn-addClass');
                })
            });
            //提交操作
            $('#levelConfirm').click(function(){
                var status = $("input[name='is_reasonable']:checked").val(),
                    vulsId = $('#hiddenId').val(),
                    content = $('#reasonConetnt').val();
                if(status ==''){
                    layer.alert('请选择一个选项')
                }else if(status == 3){
                    if(content == ''){
                        layer.alert('请简单描述等级评分不合理的理由！')
                    }
                }
                var data;
                if(status==2){
                     data ={vulsid:vulsId,status:2,desc:''};
                }else{
                     data = {vulsid:vulsId,status:3,desc:content};
                }
                $.post('{{env("APP_ROOT")}}/admin/sentencePointsVuls',data,function(msg){
                    layer.close();
                    var msg =JSON.parse(msg);
                    if(msg.code==0){
                        window.location.reload();
                    }else{
                        layer.alert(msg.msg)
                    }
                })
            });
            //编辑等级积分操作
            $('#editConfirm').click(function(){
                var level = $("#parentLevel").val(),
                    points = $("#childPoints").val(),
                    childReward = $("#childReward").val(),
                    vulsId = $('#hiddenEditId').val();
                if(level =='' || points == '' || childReward =='' ){
                    layer.alert('请确认选项是否正确！')
                }
                var data ={vulsid:vulsId,level:level,points:points,rewards:childReward};
                $.post('{{env("APP_ROOT")}}/admin/vulsReedit',data,function(msg){
                    layer.close();
                    var msg =JSON.parse(msg);
                    if(msg.code==0){
                        window.location.reload();
                    }else{
                        layer.alert(msg.msg)
                    }
                })
            });

            //获取级别下面的积分
            $('#parentLevel').change(function(){
                var v = $(this).val();
                if(!v) return false;
                appendHtml(v,-1,-1);

            });

         });
        var appendHtml = function(v,credit,reward){
            $.get('{{env("APP_ROOT")}}/admin/getPointsAjax/id/'+v,function(msg){
                if(msg){
                    var html = '',
                            htmlr = '';
                    for (var i=msg.min;i<msg.max;i++){
                        if(credit == i){
                            html +="<option value="+i+" selected>"+i+"</option>";
                        }else{
                            html +="<option value="+i+">"+i+"</option>";
                        }
                    }
                    for (var j = msg.min_r;j<msg.max_r;j++){
                        if(reward == j){
                            htmlr +="<option value="+j+" selected>"+j+"</option>";
                        }else{
                            htmlr +="<option value="+j+">"+j+"</option>";
                        }
                    }
                    $('#childPoints option,#childReward option').not(":first").remove();
                    $('#childPoints').append(html);
                    $('#childReward').append(htmlr);
                    if(credit ==-1){
                        $('#childPoints option,#childReward option').eq(1).attr('selected','selected');
                    }
                }else{
                    return false;
                }
            });
        };
        function checkForm(){
//            layer.alert(11);
            var startTime =$('#startTime').val();
            var endTime =$('#endTime').val();
            if(startTime !='' && endTime ==''){
                layer.alert("请选择结束时间！");
                return false;
            }else if(startTime =='' && endTime !=''){
                layer.alert("请选择开始时间！");
                return false;
            }
            if((new Date(endTime)) < (new Date(startTime))){
                layer.alert("结束时间不能小于开始时间！");
                return false;
            }
        }
        //等级评分确认操作
        $('.vuls-sentencepoints').each(function(){
            $(this).click(function(){
                $('#hiddenId').val($(this).attr('data-id'));
                layer.open({
                    title:'等级评分确认操作',
                    area:['600px','300px'],
                    type:1,
                    content:$('#hiddenform'),
                    cancel: function(index){
                        $('#hiddenform').hide();
                        layer.close(index);
                        return false;
                    }
                });
            });
        });
        //重新设置等级评分
        $('.vuls-vulsreedit').each(function(){
            $(this).click(function(){
                $('#hiddenEditId').val($(this).attr('data-id'));
                //让原值默认显示
                var levelVal = $(this).attr('data-level'),
                    creditVal = $(this).attr('data-credit'),
                    rewardVal = $(this).attr('data-reward');
                appendHtml(levelVal,creditVal,rewardVal);
                $("#parentLevel").find("option[value='"+levelVal+"']").attr("selected",true);
                layer.open({
                    title:'重新设置等级及评分',
                    area:['600px','350px'],
                    type:1,
                    content:$('#editForm'),
                    cancel: function(index){
                        $('#editForm').hide();
                        layer.close(index);
                        return false;
                    }
                });
            });
        });



    </script>
    <script>
        //分发


        $('.disp').each(function () {
            $(this).click(function () {
                var vuls_id = $(this).attr('data-id');
                $('#distributeId').val(vuls_id);
                var html = ' <div class="pull-left" style="margin-top: 20px;margin-left: 20px;" >'
                var htmls = '<button type="button" onclick="deledistri(this)" class="close myclose pull-left" style="border:1px solid transparent;margin:6px ;" data-id="data_id_value" aria-hidden="true"><span class="label label-default">data_name</span>&times; </button>';

                $.ajax({
                    type: "POST",
                    data: {'vuls_id': vuls_id},
                    dataType: "json",
                    url: "{{route('admin.flaw.vuls_id')}}",
                    headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                    success: function (data) {
                        var append = "";
                        console.log(data)
                        if (data.status == 2) {
                            $(data.data).each(function (index, element) {
                                var strings = htmls;
                                strings = strings.replace("data_id_value", element.users_id)
                                strings = strings.replace("data_name", element.name)
                                append += strings;
                            })
                            html += append
                            html += '<div class="clearfix"></div>'
                            html += '</div>'
                            $('#distributeform  .addaccount').html(html)
                            layer.open({
                                title: '分发',
                                area: ['700px', '400px'],
                                type: 1,
                                content: $('#distributeform').html(),
                                cancel: function (index) {
                                    $('#distributeform').hide();
                                    layer.close(index);
                                    return false;
                                },
                                success: function (layero, index) {
                                }

                            });

                        } else {
                            html += '<div class="clearfix"></div>'
                            html += '</div>'
                            $('#distributeform  .addaccount').html(html)
                            layer.open({
                                title: '分发',
                                area: ['600px', '400px'],
                                type: 1,
                                content: $('#distributeform').html(),
                                cancel: function (index) {
                                    $('#distributeform').hide();
                                    layer.close(index);
                                    return false;
                                },
                                success: function (layero, index) {
                                }
                            });
                        }
                    }
                });


            });
        });

        //查询相关信息
        $(document).on("click", ".check", function () {

            var p=$(this).parents(".parents")
            var length=p.find(".addaccount").find("button").length
            if(length>=10){
                layer.msg("最多可分发10个")
                return false
            }
            var check_value = $(this).parent(".dropdown").children("input");
            var ulli = $(this).parent(".dropdown").children("ul");
            ulli.html("")
            var values = check_value.val()   //要查询的人名
            if(!values){
                layer.msg("员工账号不能为空")
                return false
            }
            var index = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2//loading层
            $.ajax({
                type: "POST",
                data: {'name': values},
                dataType: "json",
                url: "{{route('admin.flaw.getusers')}}",
                headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                success: function (data) {
                    var htmls = '<li style="cursor:pointer;"><a onclick="details(this)"    data-user="data-account"                 data-name="data-vcname">data_user_info</a></li>';
                    var append = "";
                    if (data.status == 2) {
                        $(data.data).each(function (index, element) {
                            var strings = htmls;
                            var info = "" + element.vcName + "[" + element.vcAccount + "]" + "[" + element.vcEmail + "]" + "[" + element.vcFullName + "]";
                            strings = strings.replace("data-account", element.vcAccount)
                            strings = strings.replace("data-vcname", element.vcName)
                            strings = strings.replace("data_user_info", info)
                            append += strings;
                        })
                        layer.closeAll('loading');
                        ulli.html(append)
                    } else {
                        layer.closeAll('loading');
                        layer.msg(data.msg)
                    }
                }
            });
        })


        //        动态给生成的关闭按钮绑定事件

    </script>
    <script>
        /*查询出来的人员信息选择的时候
         * */
        function details(details) {
            var htmls = '<button type="button" onclick="deletes(this)" class="close adding myclose pull-left" style="border:1px solid transparent;margin:6px ;" data-ids="data_vac" data-user="data_van" aria-hidden="true"><span class="label label-default">data_name</span>&times; </button>';

            var vc_user = $(details).attr("data-user");
            var vc_name = $(details).attr("data-name");
            var showvalue = $(details).html()
            var parents = $(details).parent("li").parent("ul").parent(".dropdown");
            var p=$(details).parents(".parents")
            var strings = htmls;
            strings = strings.replace("data_name", vc_user)
            strings = strings.replace("data_vac", vc_user)
            strings = strings.replace("data_van", vc_name)
            parents.children("input").val("")
            p.find(".addaccount").find("button:last").next("div").remove()
            p.find(".addaccount").find("div.pull-left").append(strings)

        }

        //删除验证后的数据
        function deletes(deletes) {
            layer.confirm('确认要删除吗？', {
                btn: ['确定', '取消']//按钮
            }, function (index) {
                layer.close(index);
                $(deletes).remove()
                layer.msg("删除成功")
            })

        }


        function deledistri(distri) {
            layer.confirm('确认要删除吗？', {
                btn: ['确定', '取消']//按钮
            }, function (index) {
                layer.close(index);
                //此处请求后台程序，下方是成功后的前台处理……
                var id = $("#distributeId").val()
                var user = distri.getAttribute('data-id')
                var htmls = '<button type="button" onclick="deledistri(this)" class="close myclose pull-left" style="border:1px solid transparent;margin:6px ;" data-id="data_id_value" aria-hidden="true"><span class="label label-default">data_name</span>&times; </button>';
                var forms = $(distri).parent("div")
                var index = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2//loading层
                $.ajax({
                    type: "POST",
                    data: {'vuls_id': id, 'user': user},
                    dataType: "json",
                    url: "{{route('admin.flaw.distridel')}}",
                    headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                    success: function (data) {
                        var append = "";
                        if (data.status == 2) {
                            $(data.data).each(function (index, element) {
                                var strings = htmls;
                                strings = strings.replace("data_id_value", element.users_id)
                                strings = strings.replace("data_name", element.name)
                                append += strings;
                            })
                            forms.html(append)
                            layer.closeAll('loading');
                            layer.msg("删除成功")
                        } else {
                            layer.closeAll('loading');
                            layer.msg(data.msg)
                        }


                    },
                });
            });


        }
        ;

        /**
         * 提交
         * @param dom
         */
        function submits(dom) {
            var p=$(dom).parents(".parents")
            var buttons=p.find(".addaccount").find(".adding")
            var send="";
            var name="";
            $(buttons).each(function () {
                send+=$(this).attr("data-ids")+",";
                name+=  $(this).attr("data-user")+",";
            })
            if(!send){
                layer.msg("请添加待分发的人员信息")
            }
            var id = $("#distributeId").val()
            var aim =p.find(".addaccount")
            if (!id || !send ) {
                layer.msg("请添加待分发的人员信息")
                return false
            }
            var html = ' <div class="pull-left" style="margin-top: 20px;margin-left: 20px;" >'
            var htmls = '<button type="button" onclick="deledistri(this)" class="close myclose pull-left" style="border:1px solid transparent;margin:6px ;" data-id="data_id_value" aria-hidden="true"><span class="label label-default">data_name</span>&times; </button>';
            var index = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2//loading层
            $.ajax({
                type: "POST",
                data: {'vuls_id': id, 'name': send},
                dataType: "json",
                url: "{{route('admin.flaw.distribute')}}",
                headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                success: function (data) {
                    var append = "";
                    if (data.status == 2) {
                        $(data.data).each(function (index, element) {
                            var strings = htmls;
                            strings = strings.replace("data_id_value", element.users_id)
                            strings = strings.replace("data_name", element.name)
                            append += strings;
                        })
                        html += append
                        html += '<div class="clearfix"></div>'
                        html += '</div>'
                        aim.html(html)
                        layer.closeAll('loading');
                        layer.msg("分发成功")
                    } else {
                        layer.closeAll('loading');
                        layer.msg(data.msg)
                    }

                },

            });
        }
        //延期
        $('.vuls-delay').click(function () {
            var vuls_id = $(this).data('id');
            $("#vul-delay > input[name='vuls_id']").val(vuls_id);
            //日历控件时间限制
            $('#delayed_at').datepicker({
                autoclose: true,
                startDate: new Date()
            });
            //获取申请内容
            getDelay(vuls_id);
            delayLayer = layer.open({
                title:'延期申请',
                zIndex:10,
                type:1,
                area: ['450px', '300px'],
                content:$("#vul-delay"),
                end:function(){
                    $('#vul-delay').hide();
                    $('#delay-form')[0].reset();
                },
                success:function() {
                    $('#vul-delay > input[type="button"]').attr('id','apply-delay');
                    $("#vul-delay > input[name='delayed_at']").attr('disabled',false);
                    $("#vul-delay > textarea[name='reason']").attr('disabled',false);
                }
            });
        });
        //submit
        $("#vul-delay input[type='button']").click(function () {
            var tag = $(this).attr('id');
            if (tag=='apply-delay'){
                var fields = $("#delay-form").serializeArray();
                $.ajax(
                    {
                        url:"{{route('admin.flaw.delay')}}",
                        method:"POST",
                        data:fields,
                        headers:{'X-CSRF-TOKEN' : $('meta[name="csrf-token"]').attr('content')}
                    }
                ).fail(function(data){
                    layer.msg(data.msg);
                }).done(function(data){
                    if (data.code==0){
                        layer.msg('申请成功！');
                        window.location.reload();
                    }else{
                        layer.msg(data.msg);
                    }
                });
            }else{
                $.ajax(
                    {
                        url:"{{route('admin.flaw.auditdelay')}}",
                        method:"POST",
                        data:{"vuls_id":$('#vul-delay input[name="vuls_id"]').val()},
                        headers:{'X-CSRF-TOKEN' : $('meta[name="csrf-token"]').attr('content')}
                    }
                ).fail(function(data){
                    layer.msg(data.msg);
                }).done(function(data){
                    if (data.code==0){
                        layer.msg('审核完成！');
                        window.location.reload();
                    }else{
                        layer.msg(data.msg);
                    }
                });
            }
        });
        //审核延期
        $('.vuls-auditdelay').click(function () {
            var vuls_id = $(this).data('id');
            $("#vul-delay > input[name='vuls_id']").val(vuls_id);
            //日历控件时间限制
            $('#delayed_at').datepicker({
                autoclose: true,
                startDate: new Date()
            });
            //获取申请内容
            getDelay(vuls_id);
            //显示延期时间和理由
            delayLayer = layer.open({
                title:'延期申请',
                zIndex:10,
                type:1,
                area: ['450px', '300px'],
                content:$("#vul-delay"),
                end:function(){
                    $('#vul-delay').hide();
                    $('#delay-form')[0].reset();
                },
                success:function() {
                    //按钮控制
                    $('#vul-delay > input[type="button"]').attr('id','audit-delay');
                    $("#vul-delay > input[name='delayed_at']").attr('disabled',true);
                    $("#vul-delay > textarea[name='reason']").attr('disabled',true);
                }
            });
        });
        //获取申请内容
        function getDelay(vul_id) {
            var m1 = manage();
            var _where = {vuls_id:vul_id};
            var _header = $('meta[name="csrf-token"]').attr('content');
            m1.ajax("{{route('admin.flaw.getonedelay')}}",'get',_where,true,_header).then(function(response){
//            m1.ajax(HNA.URL+"/admin/getonedelay",'get',_where,true,_header).then(function(response){
//                $("#vul-delay > input[name='vuls_id']").val(vul_id);
                if (response.code==0){
                    $("#vul-delay > input[name='delayed_at']").val(response.data.delayed_at);
                    $("#vul-delay > textarea[name='reason']").val(response.data.reason);
                    //日历控件时间限制
                    $('#delayed_at').datepicker({
                        autoclose: true,
                        startDate: new Date(response.data.begin_time)
                    });
                    //温馨提示
                    $("#vul-delay strong").html("请选择大于修复终止日期"+response.data.begin_time);
                }
            }, function(error) {
                layer.msg(error);
            });
        }
    </script>
@endsection